import requests
from configs.config import HOST, Folderid,getTreeheaders,TESTHOST
from common.baseApi import BaseApi
import json

# 老博微云的登录接口
class BwLoginClass:
    def login(self,username,password):
        url = f'{TESTHOST}/openapi/accountService/getTokenByUP'
        headers = {
            "Content-Type": "application/x-www-form-urlencoded",
            "encrypt": "no",
            "source": "%E5%8D%9A%E5%BE%AE%E4%BA%91",   # 博微云
            "version": "1.0.0",
            "username": username,
            "password": password
        }
        res = requests.get(url, headers=headers)
        return res

#老博微云类
class OldBwyun(BaseApi):
    def getTree(self,LoginData):
        # headers = inData
        headers = {"x-openapi-computername": "computer","Authorization": ""}
        # headers['Authorization'] = 'Bearer' + ' ' + str(BwLoginClass().login(username='',password=''))
        headers['Authorization'] = 'Bearer' + ' ' + str(BwLoginClass().login(json.loads(LoginData)['username'],json.loads(LoginData)['password']).text)
        resp = self.request_send(headers=headers)
        return resp


# if __name__ == '__main__':
#     res = BwLoginClass().login(LoginData['username'],LoginData['password'])
#     print(res.text)
#     res2 = OldBwyun().getTree()
#     print(res2.json())